<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>【Js<->Flutter】</title>
</head>

<body>
<h1>【Js<->Flutter】</h1>
<br />
<input id="input" type="text" value="JavaScript -> Flutter" />
<br /><br />
<button id="button" onclick="callJsSetLanguage()" />Js设置新的语言，Flutter返回设置前的语言</button>

<script>
        var isFlutterWebViewReady = false;

        function callJsSetLanguage() {
            if (isFlutterWebViewReady) {
                // 调用 Flutter jsSetLanguage 函数
                window.flutter_inappwebview.callHandler('jsSetLanguage', { platform: 'js', language: 'en' })
                    .then(function (result) {
                        // 处理 Flutter 返回的结果
                        console.log(JSON.stringify(result));//{ platform: 'android', language: 'zh' }
                    });
            } else {
                console.log('Flutter WebView 尚未准备好，无法调用 Flutter 的 jsSetLanguage。');
            }
        }

        // 监听 flutterInAppWebViewPlatformReady 事件
        window.addEventListener("flutterInAppWebViewPlatformReady", function (event) {
            // Flutter WebView 准备好后将变量设置为 true
            isFlutterWebViewReady = true;
            // 浏览器准备好回调函数，在此处添加其他处理逻辑（如果需要）
            console.log('Js 知道 Flutter 浏览器准备好了');
        });
    </script>

</body>

</html>